package utils.com;

import android.app.Service;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;



public class NetWorkCheckUtils {

	private static Context context;
	private static WifiManager wifiManager;
	
	public static boolean isNetOpen(){
		boolean netState = true;
		try {
			ConnectivityManager connectivity = (ConnectivityManager) context
			.getSystemService(Context.CONNECTIVITY_SERVICE);
			NetworkInfo info = connectivity.getActiveNetworkInfo();
			 if (info != null & info.isConnected() & info.isAvailable() & info.getState() == NetworkInfo.State.CONNECTED) {
				 netState = true;
			}
			 else{
				 netState = false;
			 }
		} catch (Exception e) {
			e.printStackTrace();
		}
		return netState;
	}
	
	public static boolean isWIFIOpen(){
		boolean wifiState = true;
		try{
			wifiManager = (WifiManager) context.getSystemService(Service.WIFI_SERVICE); 
			wifiState = wifiManager.isWifiEnabled() ;
		}
		catch(Exception e){
			e.printStackTrace();
		}
		if(wifiState){
			return true;
		}
		else{
			return false;
		}
	}
	
	public static void openWIFIOpen(){
		try{
			wifiManager = (WifiManager) context.getSystemService(Service.WIFI_SERVICE); 
			wifiManager.setWifiEnabled(true); 
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
}
